{# ids must be unique doc-wide #}
{% set id = apos.util.generateId() %}
{% set widget = data.widget %}
{% set prependIfPrefix = apos.modules['@apostrophecms/form'].prependIfPrefix %}
{% import "fragments/utility.html" as utils with context %}

<fieldset
  data-apos-form-checkboxes
  {% if style == 'dropdown' %}data-apos-form-dropdown{% endif %}
  class="apos-form-fieldset apos-form-checkboxes--{{ style }} {{ prependIfPrefix('__fieldset') }}"
>
  <legend class="{{ prependIfPrefix('__legend') }}">
    {{ widget.fieldLabel}}
  </legend>
  {{ utils.optional(widget.required) }}
  {{ utils.required(widget.required) }}
  {% for choice in widget.choices %}
    {% set choiceId = id + apos.util.slugify(choice.value) %}
    <div class="{{ prependIfPrefix('__check-wrapper') }}">
      {{ utils.checkInput(widget, choice, choiceId, prependIfPrefix) }}
      <label class="{{ prependIfPrefix('__label') }}" for="{{ choiceId }}">
        {{ choice.label }}
      </label>
    </div>
  {% endfor %}
  <p data-apos-input-message="{{ widget.fieldName}}" hidden></p>
</fieldset>
